<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.实例 async
        // async function hello() {
        //     return "hello async";
        // }
        // //async 开头的函数  ，返回的是一个promise对象
        // console.log(hello());
        // //获取返回的promise的数据
        // hello().then(res => {
        //     console.log(res);
        // })

        //2.async await 
        function testAwait() {
            let p = new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log("text await");
                    resolve("成功");
                }, 1000);
            })
            return p;
        }

        async function hello1() {
            //await 等待 ,等待这个异步操作结束后，程序才能继续运行
            var text = await testAwait();
            console.log(text);
            console.log('hi world!');
        }
        hello1();

    </script>
</body>

</html>